package com.itheima.d4_jdk8_time;

import com.sun.tools.javac.Main;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Test5_DateTimeFormatter {
    public static void main(String[] args) {
        //创建一个日期时间格式化器
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        //var dtf = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(dtf);

        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        //使用格式化器格式化日期时间对象
        String format = dtf.format(now);
        System.out.println(format);

        String rs =now.format(dtf);
        System.out.println(rs);

        //解析日期时间字符串
        String str = "2023-03-15 15:30:00";
        LocalDateTime parse = LocalDateTime.parse(str, dtf);
        System.out.println(parse);
    }
}
